package com.itheima.d2_Collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Collectios 操作集合的工具类，注意和Collection区别开
 * Api:
 *      1.addAll 批量添加元素
 *      2.shuffle 打乱顺序
 *      3.sort 排序
 *      4.sort--->comparable 比较器排序
 */
public class demo {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
//        names.add("找找");
//        names.add("顶真");
//        names.add("黄小米叔叔");


        //addAll
        Collections.addAll(names,"找找","顶真","黄小米叔叔");
        System.out.println(names);

        //shuffle
        Collections.shuffle(names);
        System.out.println(names);

        //sort
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,5,2,33,17);
        Collections.sort(list);
        System.out.println(list);
        //====================================================

        //sort-->comparable
        List<Student> s = new ArrayList<>();
        s.add(new Student("甘雨",18,"女"));
        s.add(new Student("阿飞",17,"男"));
        s.add(new Student("找找",8,"男"));
        Collections.sort(s, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge()-o2.getAge();
            }
        });

        System.out.println(s);

    }
}
